package com.quest.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

public class CallableTest {
    private static class CallableProcessor implements Callable<Integer>{


        @Override
        public Integer call() throws Exception {
            int i = 0;
            for (; i < 100; i++) {
                System.out.println(Thread.currentThread().getName() + "->" + i);
            }
            return i;
        }
    }

    public static void main(String[] args) {
        CallableProcessor processor = new CallableProcessor();
        FutureTask<Integer> future = new FutureTask<>(processor);
        new Thread(future,"有返回值的线程").start();

        try {
            System.out.println("子线程的返回值："+future.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
